/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Lily
 * Date: 2024-09-18
 * Time: 21:47
 */
public class my_Sqrt {
    public int mySqrt(int x) {
        if (x < 1) {
            return 0;
        }
        long left = 1, right = x;
        while (left < right) {
            long min = left + (right - left + 1) / 2;
            if (min * min <= x) {
                left = min;
            } else {
                right = min - 1;
            }
        }
        return (int) left;
    }
}
